﻿using System;
using System.Windows.Input;
using MEF_Test.Bricks;
using MEF_Test.Contracts;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.Events;

namespace MEF_Test.Bricks
{
}

namespace MEF_Test.VideoRenderer.PlaybackControl
{
    public class PlaybackControlsViewModel : IPlaybackControlsViewModel
    {
        private readonly IEventAggregator _eventAggregator;

        public PlaybackControlsViewModel(IEventAggregator eventAggregator)
        {
            _eventAggregator = eventAggregator;
            MediaPlaybackStatusChangedCommand = new DelegateCommand<PlaybackStatus?>(MediaPlaybackStatusChangedCommandExecuted);

        }

        public ICommand MediaPlaybackStatusChangedCommand { get; set; }


        private void MediaPlaybackStatusChangedCommandExecuted(PlaybackStatus? status)
        {
            if (status == null)
            {
                throw new ArgumentNullException("status");
            }

            // the parameter is nullable just to be compliant with the DelegateCommand<T>.
            var nonNullableStatus = (PlaybackStatus)status ;
            _eventAggregator.GetEvent<CompositePresentationEvent<MediaPauseRequestedAggregatedEvent>>().Publish(new MediaPauseRequestedAggregatedEvent(nonNullableStatus));
        }
    }
}